package cn.edu.abtu.controller;

import cn.edu.abtu.entity.UcenterMember;
import cn.edu.abtu.entity.vo.RegisterVo;
import cn.edu.abtu.service.UcenterMemberService;
import cn.edu.abtu.vo.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@CrossOrigin
@RestController
@RequestMapping("/educenter/member")
public class UcenterController {

    @Autowired
    private UcenterMemberService ucenterMemberService;

    @GetMapping("/login")
    public ResponseData login(@RequestParam String username,
                              @RequestParam String password){
        return ucenterMemberService.login(username, password);
    }

    @PostMapping("/register")
    public ResponseData register(@RequestBody RegisterVo registerVo){
        return ucenterMemberService.register(registerVo);
    }

    @GetMapping("/getMemberInfoByToken") //根据token获取用户信息
    public ResponseData getMemberInfoByToken(HttpServletRequest request){
        return ucenterMemberService.getMemberInfoByToken(request);
    }

    @GetMapping("/getMemberInfoById/{memberId}") //根据用户ID获取用户信息
    public ResponseData getMemberInfoById(@PathVariable String memberId){
        return ucenterMemberService.getMemberInfoById(memberId);
    }

    @GetMapping("/countRegister/{date}")
    public ResponseData countRegister(@PathVariable String date){
        return ucenterMemberService.countRegister(date);
    }


}
